#!/usr/bin/python
# -*- coding: UTF-8 -*-
#cron:0 6,20 * * *
import json
import time
import random
import requests
import base64
import os
import sys
token=os.environ.get('hipc_token')


# 加载通知服务
def load_send():
    cur_path = os.path.abspath(os.path.dirname(__file__))
    sys.path.append(cur_path)
    if os.path.exists(cur_path + "/notify.py"):
        try:
            from notify import send
            return send
        except Exception as e:
            print(f"加载通知服务失败：{e}")
            return None
    else:
        print("加载通知服务失败")
        return None

def kejiman():
    headers = {
        'content-length': '87',
        'xweb_xhr': '1',
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090c11)XWEB/11437',
        'content-type': 'application/x-www-form-urlencoded',
        'accept': '*/*',
        'sec-fetch-site': 'cross-site',
        'sec-fetch-mode': 'cors',
        'sec-fetch-dest': 'empty',
        'referer': 'https://servicewechat.com/wx2f109847dd55beab/25/page-frame.html',
        'accept-encoding': 'gzip, deflate, br',
        'accept-language': 'zh-CN,zh;q=0.9'}
    payload = base64.b64decode(
        "c2lnbj0zZDA3OGI3OTM0NGFhNGRjODRkZTY3OTM1Yzg5ZTdkOCZtdV9pZD01MTMxJm11X29wZW5pZD1vM1dzMzQ3blBxUllndzltaktqTTBGdHVsdXJj")

    response0 = requests.request("POST", "https://car.mvvs.cn/ashx/xcx.ashx?method=submit.sign", headers=headers,
                                 data=payload)
    content = response0.json()["message"]
    print(response0.text)
    return content

if __name__ == '__main__':
    title = "科技漫签到通知"
    contents = kejiman()
    send_notify = load_send()
    if send_notify:
        if contents =='':
            contents=f'签到失败，请检查账户信息以及网络环境'
            print(contents)
        send_notify(title, contents)